import * as React from 'react';
import { View, Text, Button, TouchableOpacity } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';

function HomeScreen({ navigation }) {
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Text style={{fontSize: 40}}>Home Screen</Text>
      <Button
        onPress={() => navigation.navigate('Details')}
        title="跳转到详情页"
      />
    </View>
  );
}

function DetailsScreen({ navigation }) {
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Text style={{fontSize: 40}}>Details Screen</Text>
      <Button
        onPress={() => navigation.navigate('Home')}
        title="回首页"
      />
    </View>
  );
}

const Stack = createStackNavigator();

function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator initialRouteName="Home">
        <Stack.Screen 
          name="Home" 
          component={HomeScreen}
          options={{
            title: '首页', // 屏幕标题
            headerStyle: {
              backgroundColor: '#dfb', // 头部背景
              height: 50 // 头部高度
            },
            headerTitleStyle: { // 头部字体样式
              color: 'blue',
              fontSize: 20,
              fontWeight: 'bold',
            },
            // 设置头部右侧内容
            headerRight: () => (
              <TouchableOpacity onPress={() => alert('Hello')} >
                <Text
                  style={{
                    fontSize: 18, 
                    fontWeight: 'bold', 
                    color: 'black', 
                    marginRight: 20
                  }}
                >关于</Text>
              </TouchableOpacity>
            ),
          }}
        />
        <Stack.Screen name="Details" component={DetailsScreen} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

export default App;